#include <stdlib.h>
#include <stdio.h>
#include "tuple.h"

struct sTuple
{
	Key fst;
	Data snd;
};

Tuple
tuple_fromKeyData(Key k, Data d)
{
	Tuple t;
	t = (Tuple) malloc (sizeof(struct sTuple));
	if (t!=NULL)
	{
		t->fst = k;
		t->snd = d;
	}
	else
		exit(EXIT_FAILURE);

return t;
}

Key
tuple_fst(Tuple t)
{
return key_clone(t->fst);
}

Data
tuple_snd(Tuple t)
{
return data_clone(t->snd);
}

Tuple
tuple_clone(Tuple t)
{
	Tuple t2;
	t2 = (Tuple) malloc (sizeof(struct sTuple));
	if (t2 != NULL)
	{
		t2->fst = key_clone(t->fst);
		t2->snd = data_clone(t->snd);
	}
	else
		exit(EXIT_FAILURE);

return t2;
}

Tuple
tuple_destroy(Tuple t)
{
	if (t!=NULL)
	{
		t->fst = key_destroy(t->fst);
		t->snd = data_destroy(t->snd);
		free(t);
		t = NULL;
	}
return t;
}

